

<!DOCTYPE html>
<html class="writer-html5" lang="en" >
<head>
  <meta charset="utf-8" />
  
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  
  <title>LazyIO &mdash; Ceph Documentation</title>
  

  
  <link rel="stylesheet" href="../../_static/ceph.css" type="text/css" />
  <link rel="stylesheet" href="../../_static/pygments.css" type="text/css" />
  <link rel="stylesheet" href="../../_static/graphviz.css" type="text/css" />
  <link rel="stylesheet" href="../../_static/css/custom.css" type="text/css" />

  
  
    <link rel="shortcut icon" href="../../_static/favicon.ico"/>
  

  
  

  

  
  <!--[if lt IE 9]>
    <script src="../../_static/js/html5shiv.min.js"></script>
  <![endif]-->
  
    
      <script type="text/javascript" id="documentation_options" data-url_root="../../" src="../../_static/documentation_options.js"></script>
        <script src="../../_static/jquery.js"></script>
        <script src="../../_static/underscore.js"></script>
        <script src="../../_static/doctools.js"></script>
    
    <script type="text/javascript" src="../../_static/js/theme.js"></script>

    
    <link rel="index" title="Index" href="../../genindex/" />
    <link rel="search" title="Search" href="../../search/" />
    <link rel="next" title="目录分片的配置" href="../dirfrags/" />
    <link rel="prev" title="Ceph 文件系统 IO 路径" href="../cephfs-io-path/" /> 
</head>

<body class="wy-body-for-nav">

   
  <header class="top-bar">
    

















<div role="navigation" aria-label="breadcrumbs navigation">

  <ul class="wy-breadcrumbs">
    
      <li><a href="../../" class="icon icon-home"></a> &raquo;</li>
        
          <li><a href="../">Ceph 文件系统</a> &raquo;</li>
        
      <li>LazyIO</li>
    
    
      <li class="wy-breadcrumbs-aside">
        
          
            <a href="../../_sources/cephfs/lazyio.rst.txt" rel="nofollow"> View page source</a>
          
        
      </li>
    
  </ul>

  
  <hr/>
</div>
  </header>
  <div class="wy-grid-for-nav">
    
    <nav data-toggle="wy-nav-shift" class="wy-nav-side">
      <div class="wy-side-scroll">
        <div class="wy-side-nav-search"  style="background: #eee" >
          

          
            <a href="../../">
          

          
            
            <img src="../../_static/logo.png" class="logo" alt="Logo"/>
          
          </a>

          

          
<div role="search">
  <form id="rtd-search-form" class="wy-form" action="../../search/" method="get">
    <input type="text" name="q" placeholder="Search docs" />
    <input type="hidden" name="check_keywords" value="yes" />
    <input type="hidden" name="area" value="default" />
  </form>
</div>

          
        </div>

        
        <div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
          
            
            
              
            
            
              <ul class="current">
<li class="toctree-l1"><a class="reference internal" href="../../start/intro/">Ceph 简介</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../install/">安装 Ceph</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../cephadm/">Cephadm</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../rados/">Ceph 存储集群</a></li>
<li class="toctree-l1 current"><a class="reference internal" href="../">Ceph 文件系统</a><ul class="current">
<li class="toctree-l2"><a class="reference internal" href="../#cephfs">CephFS 入门</a></li>
<li class="toctree-l2"><a class="reference internal" href="../#id4">管理</a></li>
<li class="toctree-l2"><a class="reference internal" href="../#id5">挂载 CephFS</a></li>
<li class="toctree-l2 current"><a class="reference internal" href="../#id6">CephFS 内幕</a><ul class="current">
<li class="toctree-l3"><a class="reference internal" href="../mds-states/"> MDS 的各种状态</a></li>
<li class="toctree-l3"><a class="reference internal" href="../posix/"> POSIX 兼容性</a></li>
<li class="toctree-l3"><a class="reference internal" href="../mds-journaling/"> MDS 日志记录</a></li>
<li class="toctree-l3"><a class="reference internal" href="../file-layouts/"> 文件布局</a></li>
<li class="toctree-l3"><a class="reference internal" href="../mdcache/"> 分布式元数据缓存</a></li>
<li class="toctree-l3"><a class="reference internal" href="../dynamic-metadata-management/"> CephFS 内的动态元数据管理</a></li>
<li class="toctree-l3"><a class="reference internal" href="../cephfs-io-path/"> CephFS IO 路径</a></li>
<li class="toctree-l3 current"><a class="current reference internal" href="#"> LazyIO</a><ul>
<li class="toctree-l4"><a class="reference internal" href="#id1">启用 LazyIO</a></li>
<li class="toctree-l4"><a class="reference internal" href="#id2">使用 LazyIO</a></li>
</ul>
</li>
<li class="toctree-l3"><a class="reference internal" href="../dirfrags/"> 目录分片的配置</a></li>
<li class="toctree-l3"><a class="reference internal" href="../multimds/"> 多活 MDS 的配置</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="../#id7">故障排除和灾难恢复</a></li>
<li class="toctree-l2"><a class="reference internal" href="../#id9">更多细节</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="../../rbd/">Ceph 块设备</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../radosgw/">Ceph 对象网关</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../mgr/">Ceph 管理器守护进程</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../mgr/dashboard/">Ceph 仪表盘</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../api/">API 文档</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../architecture/">体系结构</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../dev/developer_guide/">开发者指南</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../dev/internals/">Ceph 内幕</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../governance/">项目管理</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../foundation/">Ceph 基金会</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../ceph-volume/">ceph-volume</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../releases/general/">Ceph 版本（总目录）</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../releases/">Ceph 版本（索引）</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../security/">Security</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../glossary/">Ceph 术语</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../jaegertracing/">Tracing</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../translation_cn/">中文版翻译资源</a></li>
</ul>

            
          
        </div>
        
      </div>
    </nav>

    <section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">

      
      <nav class="wy-nav-top" aria-label="top navigation">
        
          <i data-toggle="wy-nav-top" class="fa fa-bars"></i>
          <a href="../../">Ceph</a>
        
      </nav>


      <div class="wy-nav-content">
        
        <div class="rst-content">
        
          <div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
           <div itemprop="articleBody">
            
<div id="dev-warning" class="admonition note">
  <p class="first admonition-title">Notice</p>
  <p class="last">This document is for a development version of Ceph.</p>
</div>
  <div id="docubetter" align="right" style="padding: 5px; font-weight: bold;">
    <a href="https://pad.ceph.com/p/Report_Documentation_Bugs">Report a Documentation Bug</a>
  </div>

  
  <div class="section" id="lazyio">
<h1>LazyIO<a class="headerlink" href="#lazyio" title="Permalink to this headline">¶</a></h1>
<p>LazyIO relaxes POSIX semantics. Buffered reads/writes are allowed even when a
file is opened by multiple applications on multiple clients. Applications are
responsible for managing cache coherency themselves.</p>
<p>Libcephfs supports LazyIO since nautilus release.</p>
<div class="section" id="id1">
<h2>启用 LazyIO<a class="headerlink" href="#id1" title="Permalink to this headline">¶</a></h2>
<p>LazyIO can be enabled by following ways.</p>
<ul class="simple">
<li><p><code class="docutils literal notranslate"><span class="pre">client_force_lazyio</span></code> option enables LAZY_IO globally for libcephfs and
ceph-fuse mount.</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">ceph_lazyio(...)</span></code> and <code class="docutils literal notranslate"><span class="pre">ceph_ll_lazyio(...)</span></code> enable LAZY_IO for file handle
in libcephfs.</p></li>
</ul>
</div>
<div class="section" id="id2">
<h2>使用 LazyIO<a class="headerlink" href="#id2" title="Permalink to this headline">¶</a></h2>
<p>LazyIO includes two methods <code class="docutils literal notranslate"><span class="pre">lazyio_propagate()</span></code> and <code class="docutils literal notranslate"><span class="pre">lazyio_synchronize()</span></code>.
With LazyIO enabled, writes may not be visble to other clients until
<code class="docutils literal notranslate"><span class="pre">lazyio_propagate()</span></code> is called. Reads may come from local cache (irrespective of
changes to the file by other clients) until <code class="docutils literal notranslate"><span class="pre">lazyio_synchronize()</span></code> is called.</p>
<ul class="simple">
<li><p><code class="docutils literal notranslate"><span class="pre">lazyio_propagate(int</span> <span class="pre">fd,</span> <span class="pre">loff_t</span> <span class="pre">offset,</span> <span class="pre">size_t</span> <span class="pre">count)</span></code> - Ensures that any
buffered writes of the client, in the specific region (offset to offset+count),
has been propagated to the shared file. If offset and count are both 0, the
operation is performed on the entire file. Currently only this is supported.</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">lazyio_synchronize(int</span> <span class="pre">fd,</span> <span class="pre">loff_t</span> <span class="pre">offset,</span> <span class="pre">size_t</span> <span class="pre">count)</span></code> - Ensures that the
client is, in a subsequent read call, able to read the updated file with all
the propagated writes of the other clients. In CephFS this is facilitated by
invalidating the file caches pertaining to the inode and hence forces the
client to refetch/recache the data from the updated file. Also if the write cache
of the calling client is dirty (not propagated), lazyio_synchronize() flushes it as well.</p></li>
</ul>
<p>An example usage (utilizing libcephfs) is given below. This is a sample I/O loop for a
particular client/file descriptor in a parallel application:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="o">/*</span> <span class="n">Client</span> <span class="n">a</span> <span class="p">(</span><span class="n">ca</span><span class="p">)</span> <span class="n">opens</span> <span class="n">the</span> <span class="n">shared</span> <span class="n">file</span> <span class="n">file</span><span class="o">.</span><span class="n">txt</span> <span class="o">*/</span>
<span class="nb">int</span> <span class="n">fda</span> <span class="o">=</span> <span class="n">ceph_open</span><span class="p">(</span><span class="n">ca</span><span class="p">,</span> <span class="s2">&quot;shared_file.txt&quot;</span><span class="p">,</span> <span class="n">O_CREAT</span><span class="o">|</span><span class="n">O_RDWR</span><span class="p">,</span> <span class="mi">0644</span><span class="p">);</span>

<span class="o">/*</span> <span class="n">Enable</span> <span class="n">LazyIO</span> <span class="k">for</span> <span class="n">fda</span> <span class="o">*/</span>
<span class="n">ceph_lazyio</span><span class="p">(</span><span class="n">ca</span><span class="p">,</span> <span class="n">fda</span><span class="p">,</span> <span class="mi">1</span><span class="p">));</span>

<span class="k">for</span><span class="p">(</span><span class="n">i</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="n">i</span> <span class="o">&lt;</span> <span class="n">num_iters</span><span class="p">;</span> <span class="n">i</span><span class="o">++</span><span class="p">)</span> <span class="p">{</span>
    <span class="n">char</span> <span class="n">out_buf</span><span class="p">[]</span> <span class="o">=</span> <span class="s2">&quot;fooooooooo&quot;</span><span class="p">;</span>

    <span class="n">ceph_write</span><span class="p">(</span><span class="n">ca</span><span class="p">,</span> <span class="n">fda</span><span class="p">,</span> <span class="n">out_buf</span><span class="p">,</span> <span class="n">sizeof</span><span class="p">(</span><span class="n">out_buf</span><span class="p">),</span> <span class="n">i</span><span class="p">);</span>
    <span class="o">/*</span> <span class="n">Propagate</span> <span class="n">the</span> <span class="n">writes</span> <span class="n">associated</span> <span class="k">with</span> <span class="n">fda</span> <span class="n">to</span> <span class="n">the</span> <span class="n">backing</span> <span class="n">storage</span><span class="o">*/</span>
    <span class="n">ceph_propagate</span><span class="p">(</span><span class="n">ca</span><span class="p">,</span> <span class="n">fda</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">);</span>

    <span class="o">/*</span> <span class="n">The</span> <span class="n">barrier</span> <span class="n">makes</span> <span class="n">sure</span> <span class="n">changes</span> <span class="n">associated</span> <span class="k">with</span> <span class="nb">all</span> <span class="n">file</span> <span class="n">descriptors</span>
    <span class="n">are</span> <span class="n">propagated</span> <span class="n">so</span> <span class="n">that</span> <span class="n">there</span> <span class="ow">is</span> <span class="n">certainty</span> <span class="n">that</span> <span class="n">the</span> <span class="n">backing</span> <span class="n">file</span>
    <span class="ow">is</span> <span class="n">upto</span> <span class="n">date</span> <span class="o">*/</span>
    <span class="n">application_specific_barrier</span><span class="p">();</span>

    <span class="n">char</span> <span class="n">in_buf</span><span class="p">[</span><span class="mi">40</span><span class="p">];</span>
    <span class="o">/*</span> <span class="n">Calling</span> <span class="n">ceph_lazyio_synchronize</span> <span class="n">here</span> <span class="n">will</span> <span class="n">ascertain</span> <span class="n">that</span> <span class="n">ca</span> <span class="n">will</span>
    <span class="n">read</span> <span class="n">the</span> <span class="n">updated</span> <span class="n">file</span> <span class="k">with</span> <span class="n">the</span> <span class="n">propagated</span> <span class="n">changes</span> <span class="ow">and</span> <span class="ow">not</span> <span class="n">read</span>
    <span class="n">stale</span> <span class="n">cached</span> <span class="n">data</span> <span class="o">*/</span>
    <span class="n">ceph_lazyio_synchronize</span><span class="p">(</span><span class="n">ca</span><span class="p">,</span> <span class="n">fda</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">);</span>
    <span class="n">ceph_read</span><span class="p">(</span><span class="n">ca</span><span class="p">,</span> <span class="n">fda</span><span class="p">,</span> <span class="n">in_buf</span><span class="p">,</span> <span class="n">sizeof</span><span class="p">(</span><span class="n">in_buf</span><span class="p">),</span> <span class="mi">0</span><span class="p">);</span>

    <span class="o">/*</span> <span class="n">A</span> <span class="n">barrier</span> <span class="ow">is</span> <span class="n">required</span> <span class="n">here</span> <span class="n">before</span> <span class="n">returning</span> <span class="n">to</span> <span class="n">the</span> <span class="nb">next</span> <span class="n">write</span>
    <span class="n">phase</span> <span class="n">so</span> <span class="k">as</span> <span class="n">to</span> <span class="n">avoid</span> <span class="n">overwriting</span> <span class="n">the</span> <span class="n">portion</span> <span class="n">of</span> <span class="n">the</span> <span class="n">shared</span> <span class="n">file</span> <span class="n">still</span>
    <span class="n">being</span> <span class="n">read</span> <span class="n">by</span> <span class="n">another</span> <span class="n">file</span> <span class="n">descriptor</span> <span class="o">*/</span>
    <span class="n">application_specific_barrier</span><span class="p">();</span>
<span class="p">}</span>
</pre></div>
</div>
</div>
</div>



           </div>
           
          </div>
          <footer>
    <div class="rst-footer-buttons" role="navigation" aria-label="footer navigation">
        <a href="../dirfrags/" class="btn btn-neutral float-right" title="目录分片的配置" accesskey="n" rel="next">Next <span class="fa fa-arrow-circle-right" aria-hidden="true"></span></a>
        <a href="../cephfs-io-path/" class="btn btn-neutral float-left" title="Ceph 文件系统 IO 路径" accesskey="p" rel="prev"><span class="fa fa-arrow-circle-left" aria-hidden="true"></span> Previous</a>
    </div>

  <hr/>

  <div role="contentinfo">
    <p>
        &#169; Copyright 2016, Ceph authors and contributors. Licensed under Creative Commons Attribution Share Alike 3.0 (CC-BY-SA-3.0).

    </p>
  </div> 

</footer>
        </div>
      </div>

    </section>

  </div>
  

  <script type="text/javascript">
      jQuery(function () {
          SphinxRtdTheme.Navigation.enable(true);
      });
  </script>

  
  
    
   

</body>
</html>